package com.soft.dao;

import com.soft.IBaseDao.IBaseDao;
import com.soft.pojo.Dept;
import com.soft.utils.DBUtil;

import java.util.List;

/**
 * @author ruoxi
 * @create 2021-12-26 17:23
 */
public class DeptDaoImpl implements IBaseDao<Dept> {
    @Override
    public int add(Dept var1) {
        return DBUtil.excute("insert into dept(dno,dName,tel,dPlace,state) values(?,?,?,?,?)", var1.getDno(),var1.getdName(),var1.getTel(),var1.getdPlace(),var1.getState());
    }

    @Override
    public int del(int var1) {
        return DBUtil.excute("delete from dept where dno = ?", var1);
    }

    @Override
    public int update(Dept var1) {
        return DBUtil.excute("update dept set tel = ?,dPlace = ? where dno = ?", var1.getTel(),var1.getdPlace(),var1.getDno());
    }

    @Override
    public List<Dept> selectByAll() {
        return DBUtil.query("select * from dept", Dept.class);
    }

    @Override
    public Dept selectByKey(Dept var1) {
        return null;
    }

 
    public List<Dept> selectDeptByPage(int currentPage, int currentCount) {
        return DBUtil.query("select dno,dname,tel,dplace from dept limit ?,?", Dept.class, currentPage,currentCount);
    }

    public Dept selectDeptByDno(int dno) {
        List<Dept> depts = DBUtil.query("select * from dept where dno = ?", Dept.class, dno);
        return depts.get(0);
    }
}
